package com.zh.core;

/**
 * Created by zhaohui on 2019/11/17
 */
public class ActivityChoose {

    public static boolean[] choose(int n, int[] s, int[] f) {
        boolean[] res = new boolean[n];
        res[0] = true; //默认将第一个活动先安排
        int i = 0;
        for (int j = 1; j < n; j++) {
            // 依次检查活动是否与当前已选择的活动相容
            if (s[j] >= f[i]) {
                res[j] = true;
                i = j;
            } else {
                res[j] = false;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[][] a = {
                {1, 3, 0, 5, 3, 5, 6, 8, 8, 2, 12},
                {4, 5, 6, 7, 9, 9, 10, 11, 12, 14, 16}
        };
        int[] s = a[0];
        int[] f = a[1];
        int n = s.length;
        boolean[] res = choose(n, s, f);
        for (int i = 0; i < res.length; i++) {
            if (res[i]) {
                System.out.println(i + 1);
            }
        }
    }

}
